package study.service.user;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import study.dao.UserDao;
import study.domain.user.User;

@Service("userService")
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public class UserService {

	@Resource(name = "userDao")
	private UserDao userDao;

	/**
	 * 사용자 ID로 검색하여 사용자를 반환한다.
	 *
	 * @param id 사용자 ID
	 */
	public User getUserById(Long id) {
		return userDao.findById(id);
	}

	public User getUserByUsername(String username) {
		return userDao.findByUsername(username);
	}

	@Transactional(readOnly = false)
	public User addUser(User user) {
		return userDao.addUser(user);
	}

	@Transactional(readOnly = false)
	public void removeUser(Long id) {
		userDao.removeUser(id);
	}
}